﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.Calibration.CUiCalibrationWindow
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.Calibration.Resources;
using EngineeringInternalExtension;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using System.Windows.Markup;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands.Calibration;

public class CUiCalibrationWindow : TxWindow, IComponentConnector
{
  public CApCalibrationSet CurrentCalibrationSetUndo;
  private bool _OnTop;
  private TxWindow _ChildDialog;
  private TxWindow _ErrorDialog;
  private TxFrame tmpFrame;
  private const int SETS_GRID_APPLIED_COL = 0;
  private const int SETS_GRID_SET_NAME_COL = 1;
  private const int SETS_GRID_ROBOT_DEVICE_COL = 2;
  private const int SETS_GRID_MAINTAIN_ORIENTATION = 3;
  private const int SETS_GRID_LAST_MODIFIED_COL = 4;
  private const int SETS_GRID_DESCRIPTION_COL = 5;
  public static readonly DependencyProperty CSModelProperty = DependencyProperty.Register(nameof (CSModel), typeof (CApCalibrationSetsModel), typeof (CUiCalibrationWindow), (PropertyMetadata) new UIPropertyMetadata((PropertyChangedCallback) null));
  public static readonly DependencyProperty EditModeProperty = DependencyProperty.Register(nameof (EditMode), typeof (bool), typeof (CUiCalibrationWindow), (PropertyMetadata) new UIPropertyMetadata((object) false));
  internal System.Windows.Controls.Button NewSetButton;
  internal System.Windows.Controls.Button ApplySetButton;
  internal System.Windows.Controls.Button UnapplySetButton;
  internal System.Windows.Controls.Button DeleteSetButton;
  internal ToggleButton EmphasizeSetButton;
  internal System.Windows.Controls.Button ExportSetButton;
  internal System.Windows.Controls.DataGrid CalibrationSetGrid;
  internal System.Windows.Controls.Button EditCurrentSetButton;
  internal System.Windows.Controls.Button AcceptCurrentSetChangesButton;
  internal System.Windows.Controls.Button DiscardCurrentSetChangesButton;
  internal System.Windows.Controls.TextBox CalibrationSetInfoName;
  internal TxObjEditBoxControl CalibrationSetInfoDevice;
  internal WindowsFormsHost CalibrationSetInfoFrameHost;
  internal TxFrameComboBoxCtrl CalibrationSetInfoFrame;
  internal TxObjectGridControl CalibrationSetTargetObjects;
  internal System.Windows.Controls.DataGrid CalibrationPairsGrid;
  internal Grid CalibrationResultsGrid;
  internal TextBlock CalibrationTransformationDX;
  internal TextBlock CalibrationTransformationDY;
  internal TextBlock CalibrationTransformationDZ;
  internal TextBlock CalibrationTransformationRX;
  internal TextBlock CalibrationTransformationRY;
  internal TextBlock CalibrationTransformationRZ;
  internal TextBlock CalibrationTransformationMaxDist;
  internal TextBlock CalibrationTransformationAvgDist;
  internal TextBlock CalibrationTransformationRMS;
  internal TextBlock CalibrationErrorMessage;
  private bool _contentLoaded;

  public CApCalibrationSetsModel CSModel
  {
    get
    {
      return (CApCalibrationSetsModel) ((DependencyObject) this).GetValue(CUiCalibrationWindow.CSModelProperty);
    }
    set => ((DependencyObject) this).SetValue(CUiCalibrationWindow.CSModelProperty, (object) value);
  }

  public bool EditMode
  {
    get => (bool) ((DependencyObject) this).GetValue(CUiCalibrationWindow.EditModeProperty);
    set
    {
      ((DependencyObject) this).SetValue(CUiCalibrationWindow.EditModeProperty, (object) value);
    }
  }

  public CUiCalibrationWindow()
  {
    // ISSUE: unable to decompile the method.
  }

  private void CalibrationSetGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
    if (this.CSModel.IsEmphasized)
      this.CSModel.IsEmphasized = false;
    else if (this.CalibrationPairsGrid.SelectedItem != null)
    {
      this.CSModel.EmphasizeCalibrationPair(this.CalibrationPairsGrid.SelectedItem as CApCalibrationPair, false);
      TxApplication.RefreshDisplay();
    }
    if (this.CalibrationSetGrid.SelectedItem is CApCalibrationSet selectedItem)
      this.CSModel.SelectedCalibrationSet = selectedItem;
    if (this.CSModel.CalibrationSets.Count == 0)
    {
      this.CalibrationSetInfoDevice.Text = "";
      this.CalibrationSetInfoDevice.Object = (ITxObject) null;
      this.CalibrationSetTargetObjects.Objects = new TxObjectList();
    }
    else
    {
      this.CalibrationSetInfoDevice.Object = this.CSModel.SelectedCalibrationSet.Device;
      this.CSModel.SelectedCalibrationSet.CheckIsApplicable();
      this.CalibrationSetTargetObjects.Objects = new TxObjectList(this.CSModel.SelectedCalibrationSet.TargetObjectList);
    }
    this.UpdateFrameComboBoxCtrl();
  }

  private void CalibrationSetTargetObjects_ObjectDeleting(
    object sender,
    TxObjGridCtrl_ObjectDeletingEventArgs args)
  {
    this.CSModel.RemoveTargetObjectFromSet(this.CSModel.SelectedCalibrationSet, args.Obj);
  }

  private void CalibrationSetTargetObjects_ObjectInserted(
    object sender,
    TxObjGridCtrl_ObjectInsertedEventArgs args)
  {
    this.CSModel.AddTargetObjectToSet(this.CSModel.SelectedCalibrationSet, args.Obj);
  }

  private void CalibrationSetInfoFrame_Picked(
    object sender,
    TxFrameComboBoxCtrl_PickedEventArgs args)
  {
    if (!(args.Object is TxFrame))
      return;
    this.CSModel.SelectedCalibrationSet.RelativeToFrame = (TxFrame) args.Object;
  }

  private void CalibrationSetInfoFrame_ValidFrameSet(
    object sender,
    TxFrameComboBoxCtrl_ValidFrameSetEventArgs args)
  {
    if (!this.EditMode)
      return;
    this.CSModel.SelectedCalibrationSet.RelativeToTransformation = args.Location;
    this.ClearBoldFrame();
    this.tmpFrame = TxFrameEx.CreateFrame(new TxFrameCreationDataEx(CalibrationResources.CALIBRATION_PICKED_FRAME, args.Location, true));
    this.tmpFrame.Color = TxColor.TxColorDarkGreen;
    TxApplication.RefreshDisplay();
  }

  private void CalibrationPairsGrid_Loaded(object sender, RoutedEventArgs e)
  {
    this.CalibrationPairsGridAutoSizeColumns();
    this.CalibrationPairsGrid.Columns[0].IsReadOnly = true;
    if (this.CalibrationPairsGrid.SelectedItem == null)
      return;
    this.CSModel.EmphasizeCalibrationPair(this.CalibrationPairsGrid.SelectedItem as CApCalibrationPair, true);
    TxApplication.RefreshDisplay();
  }

  private void CalibrationSetGrid_Loaded(object sender, RoutedEventArgs e)
  {
    this.CalibrationSetGridAutoSizeColumns();
    if (this.CalibrationSetGrid.Items.Count <= 1)
      return;
    this.CalibrationSetGrid.SelectedIndex = 0;
  }

  private void CUiCalibrationWindow_Loaded(object sender, RoutedEventArgs e)
  {
    if (this._ErrorDialog == null)
      return;
    ((Window) this._ErrorDialog).Owner = (Window) this;
    ((Window) this._ErrorDialog).Show();
    this._OnTop = false;
  }

  private void CalibrationWindow_Activated(object sender, EventArgs e)
  {
    if (this._OnTop || this._ChildDialog == null)
      return;
    ((Window) this._ChildDialog).Activate();
  }

  private void CalibrationWindow_Closing(object sender, CancelEventArgs e)
  {
    if (this.EditMode)
    {
      switch (TxMessageBox.Show(string.Format(CalibrationResources.CALIBRATION_ON_CLOSE_ACCEPT_CHANGES, (object) this.CSModel.SelectedCalibrationSet.Name), CalibrationResources.CALIBRATION_NAME, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation))
      {
        case DialogResult.Cancel:
          e.Cancel = true;
          return;
        case DialogResult.Yes:
          if (!this.CheckFieldChanges())
          {
            e.Cancel = true;
            return;
          }
          break;
        default:
          this.EditMode = false;
          this.RevertChanges();
          this.ClearBoldFrame();
          TxApplication.RefreshDisplay();
          break;
      }
    }
    if (this.CSModel.IsEmphasized)
      this.CSModel.IsEmphasized = false;
    else if (this.CalibrationPairsGrid.SelectedItem != null)
    {
      this.CSModel.EmphasizeCalibrationPair(this.CalibrationPairsGrid.SelectedItem as CApCalibrationPair, false);
      TxApplication.RefreshDisplay();
    }
    if (this._ErrorDialog != null && ((FrameworkElement) this._ErrorDialog).IsLoaded)
      ((Window) this._ErrorDialog).Close();
    this.CSModel.StoreToXml();
  }

  private void CalibrationNewSetDlg_Closed(object sender, EventArgs e)
  {
    CUiCalibrationNewSetDlg calibrationNewSetDlg = sender as CUiCalibrationNewSetDlg;
    if (calibrationNewSetDlg.WindowResult)
    {
      CApCalibrationSet capCalibrationSet1 = new CApCalibrationSet();
      capCalibrationSet1.Name = calibrationNewSetDlg.CalibrationSetName.Text;
      capCalibrationSet1.Description = calibrationNewSetDlg.CalibrationSetDescription.Text;
      capCalibrationSet1.Device = calibrationNewSetDlg.CalibrationSetRobotOrDevice.Object;
      capCalibrationSet1.RelativeToFrame = (TxFrame) null;
      capCalibrationSet1.RelativeToTransformation = TxApplication.ActiveDocument.WorkingFrame;
      capCalibrationSet1.LastModified = DateTime.Now;
      bool flag = this.CSModel.CalibrationSets.Count == 0;
      CApCalibrationSet capCalibrationSet2 = new CApCalibrationSet();
      if (flag)
      {
        capCalibrationSet2.Name = "dummy";
        this.CSModel.CalibrationSets.Add(capCalibrationSet2);
        this.CSModel.SelectedCalibrationSet = capCalibrationSet2;
      }
      this.CSModel.CalibrationSets.Add(capCalibrationSet1);
      this.CSModel.SelectedCalibrationSet = capCalibrationSet1;
      if (flag)
        this.CSModel.CalibrationSets.Remove(capCalibrationSet2);
      object obj = this.CalibrationSetGrid.Items[this.CalibrationSetGrid.Items.Count - 1];
      this.CalibrationSetGrid.SelectedItem = obj;
      this.CalibrationSetGrid.Items.MoveCurrentTo(obj);
      this.CalibrationSetGrid.ScrollIntoView(obj);
      this.CalibrationSetGrid.UpdateLayout();
      this.SetEditMode(true);
    }
    this._OnTop = true;
  }

  private void NewSetButton_Click(object sender, RoutedEventArgs e)
  {
    if (this.CSModel.IsEmphasized)
      this.CSModel.IsEmphasized = false;
    this._ChildDialog = (TxWindow) new CUiCalibrationNewSetDlg(this.CSModel);
    ((Window) this._ChildDialog).Owner = (Window) this;
    ((Window) this._ChildDialog).Closed += new EventHandler(this.CalibrationNewSetDlg_Closed);
    ((Window) this._ChildDialog).Show();
    this._OnTop = false;
  }

  private void ApplySetButton_Click(object sender, RoutedEventArgs e)
  {
    this.CSModel.ApplySet(this.CSModel.SelectedCalibrationSet);
  }

  private void UnapplySetButton_Click(object sender, RoutedEventArgs e)
  {
    if (this.CSModel.SelectedCalibrationSet.IsApplied && this.CSModel.SelectedCalibrationSet.AppliedOrder != this.CSModel.AppliedOrderCounter - 1 && TxMessageBox.Show(CalibrationResources.CALIBRATION_UNAPPLY_SET, CalibrationResources.CALIBRATION_NAME, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel)
      return;
    this.CSModel.UnapplySet(this.CSModel.SelectedCalibrationSet);
  }

  private void DeleteButton_Click(object sender, RoutedEventArgs e)
  {
    string calibrationName = CalibrationResources.CALIBRATION_NAME;
    if (TxMessageBox.Show(CalibrationResources.CALIBRATION_DELETE_SET, calibrationName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No || this.CSModel.SelectedCalibrationSet == null || this.CSModel.SelectedCalibrationSet.IsApplied && TxMessageBox.Show(CalibrationResources.CALIBRATION_DELETE_APPLIED_SET, calibrationName, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
      return;
    this.CSModel.DeleteSet(this.CSModel.SelectedCalibrationSet);
    if (this.CSModel.CalibrationSets.Count != 0)
      return;
    this.CalibrationSetInfoDevice.Text = "";
    this.CalibrationSetInfoDevice.Object = (ITxObject) null;
    this.CalibrationSetInfoFrame.Enabled = true;
    this.CalibrationSetInfoFrame.Clear();
    this.CalibrationSetInfoFrame.Enabled = false;
    this.CalibrationSetTargetObjects.Objects = new TxObjectList();
  }

  private void ExportButton_Click(object sender, RoutedEventArgs e)
  {
    Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();
    string str = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
    object obj = (object) null;
    TxWindowSettings.RestoreWindowValue((TxWindow) this, "CalibrationExportLastPath", ref obj);
    if (obj != null)
      str = (string) obj;
    saveFileDialog.InitialDirectory = str;
    saveFileDialog.FileName = this.CSModel.SelectedCalibrationSet.Name + ".xls";
    saveFileDialog.Filter = $"{CalibrationResources.CALIBRATION_EXPORT_EXCEL_FORMAT} (*.xls)|*.xls|{CalibrationResources.CALIBRATION_EXPORT_ALL_FILES} (*.*)|*.*";
    saveFileDialog.AddExtension = true;
    saveFileDialog.DefaultExt = "xls";
    if (!saveFileDialog.ShowDialog().Value)
      return;
    TxWindowSettings.StoreWindowValue((TxWindow) this, "CalibrationExportLastPath", (object) saveFileDialog.FileName.Substring(0, saveFileDialog.FileName.Length - saveFileDialog.SafeFileName.Length));
    if (this.CSModel.ExportSet(this.CSModel.SelectedCalibrationSet, saveFileDialog.FileName))
    {
      int num1 = (int) TxMessageBox.Show(CalibrationResources.CALIBRATION_EXPORT_SUCCESSFUL, CalibrationResources.CALIBRATION_EXPORT_SET_BUTTON, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
    }
    else
    {
      int num2 = (int) TxMessageBox.Show(CalibrationResources.CALIBRATION_EXPORT_FAILED, CalibrationResources.CALIBRATION_EXPORT_SET_BUTTON, MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
  }

  private void EditCurrentSetButton_Click(object sender, RoutedEventArgs e)
  {
    if (this.CSModel.SelectedCalibrationSet.IsApplied)
    {
      string calibrationName = CalibrationResources.CALIBRATION_NAME;
      if (TxMessageBox.Show(CalibrationResources.CALIBRATION_UNAPPLY_BEFORE_EDIT_MODE, calibrationName, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No || this.CSModel.SelectedCalibrationSet.AppliedOrder != this.CSModel.AppliedOrderCounter - 1 && TxMessageBox.Show(CalibrationResources.CALIBRATION_UNAPPLY_SET, calibrationName, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
        return;
      this.CSModel.UnapplySet(this.CSModel.SelectedCalibrationSet);
    }
    this.SetEditMode(true);
  }

  private void AcceptCurrentSetChangesButton_Click(object sender, RoutedEventArgs e)
  {
    this.CheckFieldChanges();
  }

  private void DiscardCurrentSetChangesButton_Click(object sender, RoutedEventArgs e)
  {
    if (TxMessageBox.Show(CalibrationResources.CALIBRATION_ON_DISCARD_CHANGES, CalibrationResources.CALIBRATION_NAME, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
      return;
    if (this.CSModel.IsEmphasized)
      this.CSModel.IsEmphasized = false;
    else if (this.CalibrationPairsGrid.SelectedItem != null)
    {
      this.CSModel.EmphasizeCalibrationPair(this.CalibrationPairsGrid.SelectedItem as CApCalibrationPair, false);
      TxApplication.RefreshDisplay();
    }
    this.SetEditMode(false);
    this.RevertChanges();
  }

  private void AutoFitCalibrationPairButton_Click(object sender, RoutedEventArgs e)
  {
    this.CalibrationPairsGridAutoSizeColumns();
  }

  private void AddNewCalibrationPairButton_Click(object sender, RoutedEventArgs e)
  {
    if (this.CalibrationPairsGrid.SelectedItem != null)
    {
      this.CSModel.EmphasizeCalibrationPair(this.CalibrationPairsGrid.SelectedItem as CApCalibrationPair, false);
      TxApplication.RefreshDisplay();
    }
    this._ChildDialog = (TxWindow) new CUiCalibrationAddPairDlg(this.CSModel);
    ((Window) this._ChildDialog).Owner = (Window) this;
    ((Window) this._ChildDialog).Show();
    this._OnTop = false;
  }

  private void RemoveSelectedCalibrationPairButton_Click(object sender, RoutedEventArgs e)
  {
    this.CSModel.EmphasizeCalibrationPair(this.CSModel.SelectedCalibrationSet.CalibrationTransform.SelectedCalibrationPair, false);
    this.CSModel.SelectedCalibrationSet.RemoveCalibrationPair(this.CSModel.SelectedCalibrationSet.CalibrationTransform.SelectedCalibrationPair);
    if (this.CalibrationPairsGrid.SelectedItem != null)
      this.CSModel.EmphasizeCalibrationPair(this.CalibrationPairsGrid.SelectedItem as CApCalibrationPair, true);
    TxApplication.RefreshDisplay();
  }

  private void ClearAllCalibrationPairsButton_Click(object sender, RoutedEventArgs e)
  {
    if (TxMessageBox.Show(CalibrationResources.CALIBRATION_CURRENT_PAIRS_CLEAR_CONFIRM, CalibrationResources.CALIBRATION_NAME, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
      return;
    if (this.CSModel.IsEmphasized)
      this.CSModel.IsEmphasized = false;
    else if (this.CalibrationPairsGrid.SelectedItem != null)
    {
      this.CSModel.EmphasizeCalibrationPair(this.CalibrationPairsGrid.SelectedItem as CApCalibrationPair, false);
      TxApplication.RefreshDisplay();
    }
    this.CSModel.SelectedCalibrationSet.ClearCalibrationPairs();
  }

  private void CloseButton_Click(object sender, RoutedEventArgs e) => ((Window) this).Close();

  private void CalibrationPairsGridAutoSizeColumns()
  {
    for (int index = 0; index < this.CalibrationPairsGrid.Columns.Count; ++index)
    {
      int num = this.CalibrationPairsGrid.Columns[index].Width.IsStar ? 1 : 0;
    }
  }

  private void CalibrationSetGridAutoSizeColumns()
  {
    for (int index = 0; index < this.CalibrationSetGrid.Columns.Count; ++index)
    {
      if (!this.CalibrationSetGrid.Columns[index].Width.IsStar)
      {
        this.CalibrationSetGrid.Columns[index].Width = new DataGridLength(1.0, DataGridLengthUnitType.SizeToHeader);
        this.CalibrationSetGrid.Columns[index].Width = new DataGridLength(1.0, DataGridLengthUnitType.Auto);
      }
    }
  }

  private void ClearBoldFrame()
  {
    if (!TxFrame.op_Inequality(this.tmpFrame, (ITxObject) null))
      return;
    this.tmpFrame.Delete();
    this.tmpFrame = (TxFrame) null;
  }

  private bool CheckFieldChanges()
  {
    List<string> invalid = new List<string>();
    if (this.ValidateChanges(invalid))
    {
      this.AcceptChanges();
      this.SetEditMode(false);
      return true;
    }
    string calibrationName = CalibrationResources.CALIBRATION_NAME;
    string str1 = CalibrationResources.CALIBRATION_CURRENT_INFO_INVALID_FIELDS + "\n\n";
    foreach (string str2 in invalid)
      str1 = $"{str1}- {str2}\n";
    int num = (int) TxMessageBox.Show(str1, calibrationName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
    return false;
  }

  private bool ValidateChanges(List<string> invalid)
  {
    bool flag = true;
    if (string.IsNullOrEmpty(this.CalibrationSetInfoName.Text))
    {
      invalid.Add(CalibrationResources.CALIBRATION_CURRENT_INFO_NAME);
      flag = false;
    }
    if (!this.CalibrationSetInfoDevice.IsValid())
    {
      invalid.Add(CalibrationResources.CALIBRATION_CURRENT_INFO_ROBOT_DEVICE);
      flag = false;
    }
    if (TxTransformation.op_Equality(this.CalibrationSetInfoFrame.GetLocation(), (TxTransformation) null) || string.IsNullOrEmpty(((System.Windows.Forms.Control) this.CalibrationSetInfoFrame).Text))
    {
      invalid.Add(CalibrationResources.CALIBRATION_CURRENT_INFO_RELATIVE_FRAME);
      flag = false;
    }
    return flag;
  }

  private void AcceptChanges()
  {
    this.CSModel.SelectedCalibrationSet.Device = this.CalibrationSetInfoDevice.Object;
    this.CalibrationSetInfoName.GetBindingExpression(System.Windows.Controls.TextBox.TextProperty).UpdateSource();
    this.CSModel.SelectedCalibrationSet.LastModified = DateTime.Now;
    this.CSModel.SelectedCalibrationSet.CheckIsApplicable();
  }

  private void RevertChanges()
  {
    if (this.CurrentCalibrationSetUndo == null || this.CSModel.SelectedCalibrationSet == null)
      return;
    if (!this.CSModel.IsEmphasized && this.CalibrationPairsGrid.SelectedItem != null)
    {
      this.CSModel.EmphasizeCalibrationPair(this.CalibrationPairsGrid.SelectedItem as CApCalibrationPair, false);
      TxApplication.RefreshDisplay();
    }
    this.CSModel.Clone(this.CSModel.SelectedCalibrationSet, this.CurrentCalibrationSetUndo);
    this.CalibrationSetInfoDevice.Object = this.CSModel.SelectedCalibrationSet.Device;
    this.CalibrationSetInfoDevice.Text = this.CSModel.SelectedCalibrationSet.DeviceName;
    this.CalibrationSetTargetObjects.Objects = new TxObjectList(this.CSModel.SelectedCalibrationSet.TargetObjectList);
    this.UpdateFrameComboBoxCtrl();
  }

  private void UpdateFrameComboBoxCtrl()
  {
    bool enabled = this.CalibrationSetInfoFrame.Enabled;
    this.CalibrationSetInfoFrame.Enabled = true;
    this.CalibrationSetInfoFrame.Clear();
    this.CalibrationSetInfoFrame.AddFrame(CalibrationResources.CALIBRATION_WORKING_FRAME, TxApplication.ActiveDocument.WorkingFrame);
    this.CalibrationSetInfoFrame.SelectFrame(CalibrationResources.CALIBRATION_WORKING_FRAME);
    if (this.CSModel.SelectedCalibrationSet != null)
    {
      if (TxFrame.op_Inequality(this.CSModel.SelectedCalibrationSet.RelativeToFrame, (ITxObject) null))
      {
        this.CalibrationSetInfoFrame.AddFrame(this.CSModel.SelectedCalibrationSet.RelativeToFrame);
        this.CalibrationSetInfoFrame.SelectFrame(this.CSModel.SelectedCalibrationSet.RelativeToFrame.Name);
      }
      else if (TxTransformation.op_Inequality(this.CSModel.SelectedCalibrationSet.RelativeToTransformation, (TxTransformation) null) && TxTransformation.op_Inequality(this.CSModel.SelectedCalibrationSet.RelativeToTransformation, TxApplication.ActiveDocument.WorkingFrame))
      {
        this.CalibrationSetInfoFrame.AddFrame(CalibrationResources.CALIBRATION_PICKED_FRAME, this.CSModel.SelectedCalibrationSet.RelativeToTransformation);
        this.CalibrationSetInfoFrame.SelectFrame(CalibrationResources.CALIBRATION_PICKED_FRAME);
      }
    }
    this.CalibrationSetInfoFrame.Enabled = enabled;
  }

  private void SetEditMode(bool flag)
  {
    this.EditMode = flag;
    this.CalibrationPairsGrid.Columns[0].IsReadOnly = !flag;
    this.CalibrationSetInfoFrame.Enabled = flag;
    this.CalibrationSetTargetObjects.LoseFocus();
    ((UIElement) this.CalibrationSetTargetObjects).IsEnabled = flag;
    this.CalibrationSetTargetObjects.ListenToPick = flag;
    ((System.Windows.Forms.Control) this.CalibrationSetInfoFrame).Refresh();
    this.CalibrationSetInfoFrame.LoseFocus();
    this.CalibrationSetInfoDevice.LoseFocus();
    this.CalibrationSetInfoDevice.IsReadOnly = !flag;
    this.CSModel.SelectedCalibrationSet.CalibrationTransform.AutoCalibrate = flag;
    if (flag)
    {
      if (this.CSModel.SelectedCalibrationSet != null)
      {
        this.CurrentCalibrationSetUndo.Clone(this.CSModel.SelectedCalibrationSet);
        this.CSModel.SelectedCalibrationSet.CalibrationTransform.Calibrate();
      }
      this.CalibrationSetTargetObjects.Focus();
    }
    else
    {
      this.ClearBoldFrame();
      TxApplication.RefreshDisplay();
    }
  }

  private void WindowsFormsHost_FrameComboBoxCtrl_LostFocus(object sender, RoutedEventArgs e)
  {
    ((sender as WindowsFormsHost).Child as TxFrameComboBoxCtrl).LoseFocus();
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    System.Windows.Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/calibration/cuicalibrationwindow.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        ((Window) target).Activated += new EventHandler(this.CalibrationWindow_Activated);
        ((Window) target).Closing += new CancelEventHandler(this.CalibrationWindow_Closing);
        break;
      case 2:
        this.NewSetButton = (System.Windows.Controls.Button) target;
        this.NewSetButton.Click += new RoutedEventHandler(this.NewSetButton_Click);
        break;
      case 3:
        this.ApplySetButton = (System.Windows.Controls.Button) target;
        this.ApplySetButton.Click += new RoutedEventHandler(this.ApplySetButton_Click);
        break;
      case 4:
        this.UnapplySetButton = (System.Windows.Controls.Button) target;
        this.UnapplySetButton.Click += new RoutedEventHandler(this.UnapplySetButton_Click);
        break;
      case 5:
        this.DeleteSetButton = (System.Windows.Controls.Button) target;
        this.DeleteSetButton.Click += new RoutedEventHandler(this.DeleteButton_Click);
        break;
      case 6:
        this.EmphasizeSetButton = (ToggleButton) target;
        break;
      case 7:
        this.ExportSetButton = (System.Windows.Controls.Button) target;
        this.ExportSetButton.Click += new RoutedEventHandler(this.ExportButton_Click);
        break;
      case 8:
        this.CalibrationSetGrid = (System.Windows.Controls.DataGrid) target;
        break;
      case 9:
        this.EditCurrentSetButton = (System.Windows.Controls.Button) target;
        this.EditCurrentSetButton.Click += new RoutedEventHandler(this.EditCurrentSetButton_Click);
        break;
      case 10:
        this.AcceptCurrentSetChangesButton = (System.Windows.Controls.Button) target;
        this.AcceptCurrentSetChangesButton.Click += new RoutedEventHandler(this.AcceptCurrentSetChangesButton_Click);
        break;
      case 11:
        this.DiscardCurrentSetChangesButton = (System.Windows.Controls.Button) target;
        this.DiscardCurrentSetChangesButton.Click += new RoutedEventHandler(this.DiscardCurrentSetChangesButton_Click);
        break;
      case 12:
        this.CalibrationSetInfoName = (System.Windows.Controls.TextBox) target;
        break;
      case 13:
        this.CalibrationSetInfoDevice = (TxObjEditBoxControl) target;
        break;
      case 14:
        this.CalibrationSetInfoFrameHost = (WindowsFormsHost) target;
        this.CalibrationSetInfoFrameHost.LostFocus += new RoutedEventHandler(this.WindowsFormsHost_FrameComboBoxCtrl_LostFocus);
        break;
      case 15:
        this.CalibrationSetInfoFrame = (TxFrameComboBoxCtrl) target;
        break;
      case 16 /*0x10*/:
        this.CalibrationSetTargetObjects = (TxObjectGridControl) target;
        break;
      case 17:
        this.CalibrationPairsGrid = (System.Windows.Controls.DataGrid) target;
        break;
      case 18:
        ((System.Windows.Controls.Primitives.ButtonBase) target).Click += new RoutedEventHandler(this.AutoFitCalibrationPairButton_Click);
        break;
      case 19:
        ((System.Windows.Controls.Primitives.ButtonBase) target).Click += new RoutedEventHandler(this.AddNewCalibrationPairButton_Click);
        break;
      case 20:
        ((System.Windows.Controls.Primitives.ButtonBase) target).Click += new RoutedEventHandler(this.RemoveSelectedCalibrationPairButton_Click);
        break;
      case 21:
        ((System.Windows.Controls.Primitives.ButtonBase) target).Click += new RoutedEventHandler(this.ClearAllCalibrationPairsButton_Click);
        break;
      case 22:
        this.CalibrationResultsGrid = (Grid) target;
        break;
      case 23:
        this.CalibrationTransformationDX = (TextBlock) target;
        break;
      case 24:
        this.CalibrationTransformationDY = (TextBlock) target;
        break;
      case 25:
        this.CalibrationTransformationDZ = (TextBlock) target;
        break;
      case 26:
        this.CalibrationTransformationRX = (TextBlock) target;
        break;
      case 27:
        this.CalibrationTransformationRY = (TextBlock) target;
        break;
      case 28:
        this.CalibrationTransformationRZ = (TextBlock) target;
        break;
      case 29:
        this.CalibrationTransformationMaxDist = (TextBlock) target;
        break;
      case 30:
        this.CalibrationTransformationAvgDist = (TextBlock) target;
        break;
      case 31 /*0x1F*/:
        this.CalibrationTransformationRMS = (TextBlock) target;
        break;
      case 32 /*0x20*/:
        this.CalibrationErrorMessage = (TextBlock) target;
        break;
      case 33:
        ((System.Windows.Controls.Primitives.ButtonBase) target).Click += new RoutedEventHandler(this.CloseButton_Click);
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }
}
